home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Docs / Sources / USection.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  39.3 KB  |  1,347 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // USection.cp 
  3. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __USECTION__
  7. #include "USection.h"
  8. #endif
  9.  
  10. // MacApp
  11.  
  12. #ifndef __UADORNERS__
  13. #include "UAdorners.h"
  14. #endif
  15.  
  16. #ifndef __UAPPLICATION__
  17. //    #include "UApplication.h"
  18. #endif
  19.  
  20. #ifndef __UCOMMAND__
  21. #include "UCommand.h"
  22. #endif
  23.  
  24. #ifndef __UDEPENDENCIES__
  25. #include "UDependencies.h"
  26. #endif
  27.  
  28. #ifndef __UDESIGNATOR__
  29. #include "UDesignator.h"
  30. #endif
  31.  
  32. #ifndef __UDISPATCHER__
  33. #include "UDispatcher.h"
  34. #endif
  35.  
  36. #ifndef __UDOCUMENT__
  37. #include "UDocument.h"
  38. #endif
  39.  
  40. #ifndef __UEDITIONDOCUMENT__
  41. #include "UEditionDocument.h"
  42. #endif
  43.  
  44. #ifndef __UEVENTHANDLER__
  45. #include "UEventHandler.h"
  46. #endif
  47.  
  48. #ifndef __UEVENT__
  49. #include "UEvent.h"
  50. #endif
  51.  
  52. #ifndef __UFAILURE__
  53. #include "UFailure.h"
  54. #endif
  55.  
  56. #ifndef __UFILEBASEDDOCUMENT__
  57. #include "UFileBasedDocument.h"
  58. #endif
  59.  
  60. #ifndef __UFILE__
  61. #include "UFile.h"
  62. #endif
  63.  
  64. #ifndef __ULIST__
  65. #include "UList.h"
  66. #endif
  67.  
  68. #ifndef __UMACAPPGLOBALS__
  69. #include "UMacAppGlobals.h"
  70. #endif
  71.  
  72. #ifndef __UMACAPPUTILITIES__
  73. #include "UMacAppUtilities.h"
  74. #endif
  75.  
  76. #ifndef __UMEMORY__
  77. #include "UMemory.h"
  78. #endif
  79.  
  80. #ifndef __UPATCH__
  81. #include "UPatch.h"
  82. #endif
  83.  
  84. #ifndef __USTREAM__
  85. #include "UStream.h"
  86. #endif
  87.  
  88. #ifndef __UVIEW__
  89. #include "UView.h"
  90. #endif
  91.  
  92. // Toolbox
  93.  
  94. #ifndef __ALIASES__
  95. #include <Aliases.h>
  96. #endif
  97.  
  98. #ifndef __APPLEEVENTS__
  99. #include <AppleEvents.h>
  100. #endif
  101.  
  102. #ifndef __BALLOONS__
  103. #include <Balloons.h>
  104. #endif
  105.  
  106. #ifndef __DIALOGS__
  107. #include <Dialogs.h>
  108. #endif
  109.  
  110. #ifndef __ERRORS__
  111. #include <Errors.h>
  112. #endif
  113.  
  114. #ifndef __RESOURCES__
  115. #include <Resources.h>
  116. #endif
  117.  
  118. #ifndef __TEXTEDIT__
  119. #include <TextEdit.h>
  120. #endif
  121.  
  122.  
  123.  
  124. //========================================================================================
  125. // CLASS TSection
  126. //========================================================================================
  127. #undef Inherited
  128. #define Inherited TObject
  129.  
  130. #pragma segment MASectionNonRes
  131. MA_DEFINE_CLASS_M1(TSection, Inherited);
  132.  
  133. //----------------------------------------------------------------------------------------
  134. // TSection::TSection:
  135. //----------------------------------------------------------------------------------------
  136. #pragma segment ConstructorRes
  137.  
  138. TSection::TSection()
  139. {
  140.     fDocument = NULL;
  141.     fDesignator = NULL;
  142.     fSectionHandle = NULL;
  143.     fRsrcID = 0;
  144.     fLastEditionInfo.crDate = 0;
  145.     fLastEditionInfo.mdDate = 0;
  146.     fLastEditionInfo.fdCreator = '\?\?\?\?';
  147.     fLastEditionInfo.fdType = '\?\?\?\?';
  148.     fCanceled = FALSE;
  149.     fFound = FALSE;
  150.     fNewSection = TRUE;
  151. } // TSection::TSection
  152.  
  153. //----------------------------------------------------------------------------------------
  154. // TSection::ISection: 
  155. //----------------------------------------------------------------------------------------
  156. #pragma segment MASectionRes
  157.  
  158. void TSection::ISection(TEditionDocument* itsDocument,
  159.                                TDesignator* itsDesignator,
  160.                                SectionHandle itsSectionHandle,
  161.                                short itsRsrcID)
  162.  
  163. {
  164.     this->IObject();
  165.  
  166.     fDocument = itsDocument;
  167.     fDesignator = itsDesignator;
  168.     fSectionHandle = itsSectionHandle;
  169.     fRsrcID = itsRsrcID;
  170.     fFound = kEditionFound;
  171.     fCanceled = kDontCancel;
  172.     fNewSection = TRUE;                            // yes it is new 
  173. } // TSection::ISection 
  174.  
  175. //----------------------------------------------------------------------------------------
  176. // TSection::Associate: 
  177. //----------------------------------------------------------------------------------------
  178. #pragma segment MASectionWrite
  179.  
  180. void TSection::Associate(TFile* aFile)
  181. {
  182. #if qDebug
  183.     if (!fSectionHandle)
  184.         ProgramBreak("###fSectionHandle is NULL");
  185. #endif
  186.  
  187.     // get the FSSpec for the file in question
  188.     FSSpec itsFSSpec;
  189.     aFile->GetFileSpec(itsFSSpec);
  190.     
  191.     // associate this section object with the FSSpec
  192.     OSErr err = AssociateSection(fSectionHandle, &itsFSSpec);
  193.     
  194.     // Allow fnfErr if we're a subscriber. This accounts for the situation in which the
  195.     // user has canceled the publisher so that its edition container file is no longer
  196.     // there. Should this be done in an override, e.g. TSubscriber::Associate() ???
  197.     if (this->GetSectionType() == stSubscriber)
  198.     {
  199.         if ((err != noErr) && (err != fnfErr))
  200.             FailOSErr(err);
  201.     }
  202.     else
  203.         FailOSErr(err);
  204.  
  205.     // assume it's changed
  206.     this->MarkAsChanged();
  207. } // TSection::Associate 
  208.  
  209. //----------------------------------------------------------------------------------------
  210. // TSection::AttachSectionHandle: 
  211. //----------------------------------------------------------------------------------------
  212. #pragma segment MASectionRes
  213.  
  214. void TSection::AttachSectionHandle(SectionHandle itsSectionHandle)
  215. {
  216. #if qDebug
  217.     if (fSectionHandle)
  218.         ProgramBreak("###about to overwrite fSectionHandle");
  219. #endif
  220.  
  221.     fSectionHandle = itsSectionHandle;
  222. } // TSection::AttachSectionHandle 
  223.  
  224. //----------------------------------------------------------------------------------------
  225. // TSection::DoNeedDiskSpace: 
  226. //----------------------------------------------------------------------------------------
  227. #pragma segment MASectionWrite
  228.  
  229. void TSection::DoNeedDiskSpace(long& ,
  230.                                       long& rsrcForkBytes)
  231. {
  232.     if (fSectionHandle)
  233.     {
  234.         EditionInfoRecord editionInfo;
  235.     
  236.         FailOSErr(GetEditionInfo(fSectionHandle, &editionInfo));
  237.         CStr255 rsrcName(editionInfo.container.theFile.name);
  238.         rsrcForkBytes += (3 * (rsrcName.Length() + kLengthByte));
  239.         
  240.         rsrcForkBytes += kRsrcOverhead + GetHandleSize((Handle)fSectionHandle);
  241.         rsrcForkBytes += kRsrcOverhead + GetHandleSize((Handle)(*fSectionHandle)->alias);
  242.  
  243.         TCountingStream* aStream;
  244.         aStream = new TCountingStream;
  245.         aStream->ICountingStream();
  246.         aStream->WriteStreamObject(fDesignator, kStandardObject);
  247.         rsrcForkBytes += kRsrcOverhead + aStream->GetSize();
  248.         aStream->Free();
  249.     }
  250. } // TSection::DoNeedDiskSpace 
  251.  
  252. //----------------------------------------------------------------------------------------
  253. // TSection::Free: 
  254. //----------------------------------------------------------------------------------------
  255. #pragma segment MASectionClose
  256.  
  257. TSection::~TSection()
  258. {
  259.     fDocument->RemoveSection(this);
  260.  
  261.     this->UnRegister();
  262.     fDesignator = (TDesignator *)FreeIfObject(fDesignator);
  263.     fSectionHandle = DisposeIfSectionHandle(fSectionHandle);
  264. } // TSection::Free 
  265.  
  266. //----------------------------------------------------------------------------------------
  267. // TSection::GetEditionName: 
  268. //----------------------------------------------------------------------------------------
  269. #pragma segment MASectionRes
  270.  
  271. void TSection::GetEditionName(CStr255& name)
  272. {
  273.     this->UpdateEditionInfo();
  274.     name = fLastEditionInfo.container.theFile.name;
  275. } // TSection::GetEditionName 
  276.  
  277. //----------------------------------------------------------------------------------------
  278. // TSection::GetFileHandler: 
  279. //----------------------------------------------------------------------------------------
  280.  
  281. //----------------------------------------------------------------------------------------
  282. // TSection::GetSectionType: 
  283. //----------------------------------------------------------------------------------------
  284. #pragma segment MASectionRes
  285.  
  286. SectionType TSection::GetSectionType()
  287. {
  288.     if (fSectionHandle)
  289.         return (*fSectionHandle)->kind;
  290.     else
  291.         return (SectionType) - 1;
  292. } // TSection::GetSectionType 
  293.  
  294. //----------------------------------------------------------------------------------------
  295. // TSection::GetUpdateMode: 
  296. //----------------------------------------------------------------------------------------
  297. #pragma segment MASectionRes
  298.  
  299. UpdateMode TSection::GetUpdateMode()
  300. {
  301.     if (fSectionHandle)
  302.         return (*fSectionHandle)->mode;
  303.     else
  304.         return (UpdateMode) - 1;
  305. } // TSection::GetUpdateMode 
  306.  
  307. //----------------------------------------------------------------------------------------
  308. // TSection::DoRead: 
  309. //----------------------------------------------------------------------------------------
  310. #pragma segment MASectionRead
  311.  
  312. void TSection::DoRead(TFile* aFile)
  313. {
  314.     if (!aFile->IsRsrcForkOpen())
  315.     {
  316. #if qDebug
  317.         ProgramBreak("###resource fork isn't open");
  318. #endif
  319.     }
  320.     else
  321.     {
  322.         // set up for failure handler 
  323.         MAVolatileInit(TResourceStream*, aResourceStream, NULL);
  324.         MAVolatile(short, oldResFile);
  325.         
  326.         fSectionHandle = NULL;
  327.         fDesignator = NULL;
  328.  
  329.         FailInfo fi;
  330.         Try(fi)
  331.         {
  332.             Handle aHandle;
  333.  
  334.             oldResFile = aFile->UseResource();    // set the current ResFile
  335.  
  336.             // read in the section handle from a rSectionType resource 
  337.             aHandle = Get1Resource(rSectionType, fRsrcID);
  338.             FailNILResource(aHandle);
  339.             DetachResource(aHandle);
  340.             FailResError();
  341.             fSectionHandle = (SectionHandle)aHandle;
  342.             (*fSectionHandle)->alias = NULL;    // so failure handler works
  343.  
  344.             // read in the alias handle from a rAliasType resource 
  345.             aHandle = Get1Resource(rAliasType, fRsrcID);
  346.             FailNILResource(aHandle);
  347.             DetachResource(aHandle);
  348.             FailResError();
  349.             (*fSectionHandle)->alias = (AliasHandle)aHandle;
  350.             
  351.             // read in the associated designator 
  352.             aResourceStream = new TResourceStream;
  353.             aResourceStream->IResourceStream(kDesignatorResType, fRsrcID);
  354.  
  355.             FailInfo innerfi;
  356.             Try(innerfi)
  357.             {
  358.                 TDesignator* aDesignator = NULL;
  359.                 if (aResourceStream->ReadStreamObject((TObject*&) aDesignator))
  360.                     fDesignator = aDesignator;
  361. #if qDebugMsg
  362.                 else
  363.                     ProgramBreak("###Unknown TDesignator in TSection::DoRead.");
  364. #endif
  365.                 innerfi.Success();
  366.             }
  367.             else
  368.             {
  369.                 aResourceStream = (TResourceStream *)FreeIfObject(aResourceStream);
  370.                 fSectionHandle = DisposeIfSectionHandle(fSectionHandle);
  371.                 // We don't need to free aDesignator here because it would have previously been freed
  372.                 innerfi.ReSignal();
  373.             }
  374.  
  375.             aResourceStream->Free();
  376.  
  377.             MAUseResFile(oldResFile);                // restore the current ResFile
  378.  
  379.             fi.Success();
  380.         }
  381.         else    // Recover
  382.         {
  383.             fSectionHandle = DisposeIfSectionHandle(fSectionHandle);
  384.  
  385.             MAUseResFile(oldResFile);                // restore the current ResFile
  386.  
  387.             fi.ReSignal();                        // Optional. Omit to continue.
  388.         }
  389.  
  390.         // register the section 
  391.         fNewSection = FALSE;                    // no it is not new 
  392.         OSErr err = this->Register();
  393.         fFound = (err == containerNotFoundWrn) ? kEditionNotFound : kEditionFound;
  394.         if ((err != containerNotFoundWrn) && (err != notThePublisherWrn) && (err != multiplePublisherWrn))
  395.             FailOSErr(err);
  396.         
  397.         // associate the section correctly
  398.         this->Associate(aFile);
  399.     }
  400. } // TSection::DoRead 
  401.  
  402. //----------------------------------------------------------------------------------------
  403. // TSection::DoWrite: 
  404. //----------------------------------------------------------------------------------------
  405. #pragma segment MASectionWrite
  406.  
  407. void TSection::DoWrite(TFile* aFile,
  408.                               Boolean /* makingCopy */)
  409. {
  410.     if (!fSectionHandle)
  411.     {
  412. #if qDebug
  413.         ProgramBreak("###TSection::DoWrite: fSectionHandle is NULL");
  414. #endif
  415.         return;
  416.     }
  417.  
  418.     if (!aFile->IsRsrcForkOpen())
  419.     {
  420. #if qDebug
  421.         ProgramBreak("###TSection::DoWrite: resource fork isn't open");
  422. #endif
  423.         return;
  424.     }
  425.  
  426.     MAVolatile(short, oldResFile);
  427.  
  428.     FailInfo fi;
  429.     Try(fi)
  430.     {
  431.         //MAVolatile(Handle, aHandle);
  432.         Handle aHandle;    // can't be volatile because it is passed by reference
  433.  
  434.         oldResFile = aFile->UseResource();    // set the current ResFile
  435.  
  436.         // associate with the correct current file
  437.         TFile* currentFile = this->GetCurrentFile(aFile);
  438.         this->Associate(currentFile);
  439.  
  440.         // prepare to write out our section resources 
  441.         EditionInfoRecord editionInfo;
  442.         FailOSErr(GetEditionInfo(fSectionHandle, &editionInfo));
  443.         CStr255 rsrcName = editionInfo.container.theFile.name;
  444.  
  445.         // add the alias handle as an rAliasType resource 
  446.         aHandle = (Handle)(*fSectionHandle)->alias;
  447.         PermHandToHand(aHandle);
  448.         FailInfo innerfi1;
  449.         Try(innerfi1)
  450.         {
  451.             MAAddResource(aHandle, rAliasType, fRsrcID, rsrcName);
  452.             FailResError();
  453.             innerfi1.Success();
  454.         }
  455.         else
  456.         {
  457.             aHandle = DisposeIfHandle(aHandle);
  458.             innerfi1.ReSignal();
  459.         }
  460.  
  461.         // add the section handle as an rSectionType resource 
  462.         aHandle = (Handle)fSectionHandle;
  463.         PermHandToHand(aHandle);
  464.         FailInfo innerfi2;
  465.         Try(innerfi2)
  466.         {
  467.             MAAddResource(aHandle, rSectionType, fRsrcID, rsrcName);
  468.             FailResError();
  469.             innerfi2.Success();
  470.         }
  471.         else
  472.         {
  473.             aHandle = DisposeIfHandle(aHandle);
  474.             innerfi2.ReSignal();
  475.         }
  476.  
  477.         // ask the designator to write its specification to a TResourceStream 
  478.         aHandle = NewPermHandle(2);
  479.         FailInfo innerfi3;
  480.         Try(innerfi3)
  481.         {
  482.             MAAddResource(aHandle, kDesignatorResType, fRsrcID, rsrcName);
  483.             FailResError();
  484.             innerfi3.Success();
  485.         }
  486.         else
  487.         {
  488.             aHandle = DisposeIfHandle(aHandle);
  489.             innerfi3.ReSignal();
  490.         }
  491.         WriteResource(aHandle);
  492.         ReleaseResource(aHandle);
  493.  
  494.         // write the designator to a resource (using a stream)
  495.         MAVolatileInit(TResourceStream*, aResourceStream, new TResourceStream);
  496.         aResourceStream->IResourceStream(kDesignatorResType, fRsrcID);
  497.         
  498.         FailInfo innerfi4;
  499.         Try(innerfi4)
  500.         {
  501.             aResourceStream->WriteStreamObject(fDesignator, kStandardObject);
  502.             innerfi4.Success();
  503.         }
  504.         else
  505.         {
  506.             aResourceStream = (TResourceStream *)FreeIfObject(aResourceStream);
  507.             innerfi4.ReSignal();
  508.         }
  509.  
  510.         aResourceStream = (TResourceStream *)FreeIfObject(aResourceStream);
  511.  
  512.         MAUseResFile(oldResFile);                // restore the current ResFile
  513.  
  514.         fNewSection = FALSE;                // no it is not new 
  515.         fi.Success();
  516.     }
  517.     else    // Recover
  518.     {
  519.         MAUseResFile(oldResFile);                // restore the current ResFile
  520.         fi.ReSignal();                        // Optional. Omit to continue.
  521.     }
  522. } // TSection::DoWrite 
  523.  
  524. //----------------------------------------------------------------------------------------
  525. // TSection::Delete: 
  526. //----------------------------------------------------------------------------------------
  527. #pragma segment MASectionWrite
  528.  
  529. void TSection::Delete()
  530. {
  531. } // TSection::Delete 
  532.  
  533. //----------------------------------------------------------------------------------------
  534. // TSection::IsCanceled: 
  535. //----------------------------------------------------------------------------------------
  536. #pragma segment MASectionRes
  537.  
  538. Boolean TSection::IsCanceled()
  539. {
  540.     return fCanceled;
  541. } // TSection::IsCanceled 
  542.  
  543. //----------------------------------------------------------------------------------------
  544. // TSection::IsChanged: this method is never called: it is overridden for both TPublisher
  545. // & TSubscriber
  546. //----------------------------------------------------------------------------------------
  547. #pragma segment MANever
  548.  
  549. Boolean TSection::IsChanged()
  550. {
  551.     return FALSE;
  552. } // TSection::IsChanged 
  553.  
  554. //----------------------------------------------------------------------------------------
  555. // TSection::MarkAsChanged: this method is never called: it is overridden for both
  556. // TPublisher & TSubscriber
  557. //----------------------------------------------------------------------------------------
  558. #pragma segment MANever
  559.  
  560. void TSection::MarkAsChanged()
  561. {
  562. } // TSection::MarkAsChanged 
  563.  
  564. //----------------------------------------------------------------------------------------
  565. // TSection::IsRegistered: 
  566. //----------------------------------------------------------------------------------------
  567. #pragma segment MASectionRes
  568.  
  569. Boolean TSection::IsRegistered()
  570. {
  571.     // it's registered if the Edition Manager thinks it's registered 
  572.     if (fSectionHandle)
  573.         return IsRegisteredSection(fSectionHandle) == noErr;
  574.     else
  575.         return FALSE;
  576. } // TSection::IsRegistered 
  577.  
  578. //----------------------------------------------------------------------------------------
  579. // TSection::Register: 
  580. //----------------------------------------------------------------------------------------
  581. #pragma segment MASectionRes
  582.  
  583. OSErr TSection::Register()
  584. {
  585.     OSErr err = noErr;
  586.  
  587.     if (!this->IsRegistered())
  588.     {
  589.         TFile* aFile = (fDocument != NULL) ? fDocument->GetFile() : NULL;
  590.         if (aFile)
  591.         {
  592.             FSSpec theFileSpec;
  593.             
  594.             Boolean aliasWasUpdated;
  595.             aFile->GetFileSpec(theFileSpec);
  596.             err = RegisterSection(&theFileSpec, fSectionHandle, &aliasWasUpdated);
  597.  
  598.             // if aliasWasUpdated, mark section as changed so that user saves changed edition 
  599.             if (aliasWasUpdated)
  600.                 this->MarkAsChanged();
  601.  
  602.             // if RegisterSection was successful, update edition info 
  603.             if (err == noErr)
  604.                 this->UpdateEditionInfo();
  605.         }
  606.         else
  607.         {
  608.             err = fnfErr;
  609. #if qDebug
  610.             ProgramBreak("how to call RegisterSection if there isn't a TFile???");
  611. #endif
  612.         }
  613.     }
  614.     return err;
  615. } // TSection::Register 
  616.  
  617. //----------------------------------------------------------------------------------------
  618. // TSection::UnRegister: 
  619. //----------------------------------------------------------------------------------------
  620. #pragma segment MASectionRes
  621.  
  622. void TSection::UnRegister()
  623. {
  624.     if (this->IsRegistered())
  625.         FailOSErr(UnRegisterSection(fSectionHandle));
  626. } // TSection::UnRegister 
  627.  
  628. //----------------------------------------------------------------------------------------
  629. // TSection::UpdateEditionInfo: 
  630. //----------------------------------------------------------------------------------------
  631. #pragma segment MASectionRes
  632.  
  633. void TSection::UpdateEditionInfo()
  634. {
  635.     EditionInfoRecord editionInfo;
  636.  
  637.     if (this->IsRegistered() && (GetEditionInfo(fSectionHandle, &editionInfo) == noErr))
  638.         fLastEditionInfo = editionInfo;
  639. } // TSection::UpdateEditionInfo 
  640.  
  641. //----------------------------------------------------------------------------------------
  642. // TSection::CancelSection: 
  643. //----------------------------------------------------------------------------------------
  644. #pragma segment MASectionRes
  645.  
  646. void TSection::CancelSection(Boolean cancel)
  647. {
  648.     OSErr err;
  649.  
  650.     if (cancel != fCanceled)
  651.         if (cancel == kCancel)
  652.         {
  653.             this->UpdateEditionInfo();            // We will be able to delete it later.
  654.             this->UnRegister();
  655.             fCanceled = kCancel;                // it IS canceled 
  656.         }
  657.         else
  658.         {
  659.             err = this->Register();
  660.             if ((err != containerNotFoundWrn) && (err != notThePublisherWrn) && (err != multiplePublisherWrn))
  661.                 FailOSErr(err);
  662.             fCanceled = kDontCancel;            // it IS !canceled 
  663.         }
  664. } // TSection::CancelSection 
  665.  
  666. //----------------------------------------------------------------------------------------
  667. // TSection::GetCurrentFile: 
  668. //----------------------------------------------------------------------------------------
  669. #pragma segment MASectionWrite
  670.  
  671. TFile* TSection::GetCurrentFile(TFile* aFile)
  672. {
  673.     // This looks strange but it should be correct. The idea is to associate the
  674.     // section with the correct disk file. If it's a newly saved document, associate
  675.     // with the file that is passed in, this will be the temporary file; if it's not a
  676.     // new save, associate it with the current file that the file handler owns.
  677.     
  678.     if (fDocument && fDocument->FileExists())
  679.         return fDocument->GetFile();
  680.     else
  681.         return aFile;
  682. } // TSection::GetCurrentFile 
  683.  
  684.  
  685. //========================================================================================
  686. // CLASS TPublisher
  687. //========================================================================================
  688. #undef Inherited
  689. #define Inherited TSection
  690.  
  691. #pragma segment MASectionNonRes
  692. MA_DEFINE_CLASS_M1(TPublisher, Inherited);
  693.  
  694. //----------------------------------------------------------------------------------------
  695. // TPublisher::TPublisher: Empty constructor to satisfy the compiler.
  696. //----------------------------------------------------------------------------------------
  697. #pragma segment ConstructorRes
  698.  
  699. TPublisher::TPublisher()
  700. {
  701. } // TPublisher::TPublisher
  702.  
  703. //----------------------------------------------------------------------------------------
  704. // TPublisher destructor
  705. //----------------------------------------------------------------------------------------
  706. #pragma segment MADestructorRes
  707.  
  708. TPublisher::~TPublisher()
  709. {
  710. }
  711.  
  712. //----------------------------------------------------------------------------------------
  713. // TPublisher::IPublisher: 
  714. //----------------------------------------------------------------------------------------
  715. #pragma segment MASectionNonRes
  716.  
  717. void TPublisher::IPublisher(TEditionDocument* itsDocument,
  718.                                    TDesignator* itsDesignator,
  719.                                    SectionHandle itsSectionHandle,
  720.                                    short itsRsrcID)
  721. {
  722.     this->ISection(itsDocument, itsDesignator, itsSectionHandle, itsRsrcID);
  723. } // TPublisher::IPublisher 
  724.  
  725. //----------------------------------------------------------------------------------------
  726. // TPublisher::DoUpdate: 
  727. //----------------------------------------------------------------------------------------
  728. #pragma segment MASectionRes
  729.  
  730. void TPublisher::DoUpdate(ChangeID theChange,
  731.                                  TObject* changedObject,
  732.                                  TObject* changedBy,
  733.                                  TDependencySpace* dependencySpace)// override 
  734. {
  735.     if (theChange != kNoChange)
  736.         this->MarkAsChanged();
  737.  
  738.     Inherited::DoUpdate(theChange, changedObject, changedBy,dependencySpace);
  739. } // TPublisher::DoUpdate 
  740.  
  741. //----------------------------------------------------------------------------------------
  742. // TPublisher::Publish: 
  743. //----------------------------------------------------------------------------------------
  744. #pragma segment MASectionWrite
  745.  
  746. void TPublisher::Publish(TFile* aFile)
  747. {
  748.     FSSpec aFSSpec;
  749.     FSSpecPtr aFSSpecPtr = NULL;
  750.     OSErr err;
  751.  
  752.     MAVolatile(TSectionStream*, aSectionStream);
  753.     //MAVolatile(EditionRefNum, refNum);
  754.     EditionRefNum refNum;    // can't be volatile because it is passed by reference
  755.  
  756.     if (aFile && aFile->HasValidFileSpec())
  757.     {
  758.         aFile->GetFileSpec(aFSSpec);
  759.         aFSSpecPtr = &aFSSpec;
  760.     }
  761.  
  762.     err = OpenNewEdition(fSectionHandle, gDispatcher->fCreator, aFSSpecPtr, &refNum);
  763.     if (err == noErr)                    // DON'T signal failure if the OpenNewEdition
  764.                                         // fails, just continue without publishing.
  765.     {
  766.         FailInfo fi;
  767.         Try(fi)
  768.         {
  769.             // Create a section stream to write the published data to, and publish the
  770.             // document's private type first:
  771.             aSectionStream = NULL;
  772.             aSectionStream = new TSectionStream;
  773.             aSectionStream->ISectionStream(refNum, fDocument->fScrapType);
  774.             
  775.             FailInfo innerfi;
  776.             Try(innerfi)
  777.             {
  778.                 fDocument->DoWriteData(fDocument->fScrapType, fDesignator, aSectionStream);
  779.     
  780.                 // Publish the rest of the data types. The order in which the application
  781.                 // publishes to the edition container file indicates to the client application
  782.                 // the preferred order for subscribers! So, publish the TEXT or PICT or 'snd '
  783.                 // (at least one is required) in the order prefered.
  784.     
  785.                 // N.B.: The Edition Manager will set the edition container file's file type
  786.                 // according to which type was published first: 'edtp' if PICT was published
  787.                 // first, 'edtt' if TEXT was published first, and 'edts' if 'snd ' was
  788.                 // published first.
  789.     
  790.                 if (fDocument->GetPublishPreference() == 'PICT')
  791.                 {
  792.                     aSectionStream->Reset('PICT', 0);
  793.                     fDocument->DoWriteData('PICT', fDesignator, aSectionStream);
  794.                     aSectionStream->Reset('TEXT', 0);
  795.                     fDocument->DoWriteData('TEXT', fDesignator, aSectionStream);
  796.                     aSectionStream->Reset('snd ', 0);
  797.                     fDocument->DoWriteData('snd ', fDesignator, aSectionStream);
  798.                 }
  799.                 else if (fDocument->GetPublishPreference() == 'TEXT')
  800.                 {
  801.                     aSectionStream->Reset('TEXT', 0);
  802.                     fDocument->DoWriteData('TEXT', fDesignator, aSectionStream);
  803.                     aSectionStream->Reset('PICT', 0);
  804.                     fDocument->DoWriteData('PICT', fDesignator, aSectionStream);
  805.                     aSectionStream->Reset('snd ', 0);
  806.                     fDocument->DoWriteData('snd ', fDesignator, aSectionStream);
  807.                 }
  808.                 else if (fDocument->GetPublishPreference() == 'snd ')
  809.                 {
  810.                     aSectionStream->Reset('snd ', 0);
  811.                     fDocument->DoWriteData('snd ', fDesignator, aSectionStream);
  812.                     aSectionStream->Reset('TEXT', 0);
  813.                     fDocument->DoWriteData('TEXT', fDesignator, aSectionStream);
  814.                     aSectionStream->Reset('PICT', 0);
  815.                     fDocument->DoWriteData('PICT', fDesignator, aSectionStream);
  816.                 }
  817.                 innerfi.Success();
  818.             }
  819.             else
  820.             {
  821.                 // Free the stream
  822.                 aSectionStream = (TSectionStream*)FreeIfObject(aSectionStream);
  823.                 innerfi.ReSignal();
  824.             }
  825.             
  826.             // Free the stream
  827.             aSectionStream->Free();
  828.  
  829.             fi.Success();
  830.         }
  831.         else    // Recover
  832.         {
  833.             // If there is a failure during publishing close the edition file without
  834.             // saving the changes (pass false for successful). This ensures that the
  835.             // publisher will get a shot at publishing again later.
  836.             err = CloseEdition(refNum, FALSE);
  837.  
  838.             fi.ReSignal();                        // Optional. Omit to continue.
  839.         }
  840.         // close the edition file, passing true for the successful parameter 
  841.         FailOSErr(CloseEdition(refNum, TRUE));
  842.     }
  843. } // TPublisher::Publish 
  844.  
  845. //----------------------------------------------------------------------------------------
  846. // TPublisher::DoWrite: 
  847. //----------------------------------------------------------------------------------------
  848. #pragma segment MASectionWrite
  849.  
  850. void TPublisher::DoWrite(TFile* aFile,
  851.                                 Boolean makingCopy)// override 
  852.  
  853. {
  854.     Inherited::DoWrite(aFile, makingCopy);
  855.  
  856.     if ((!fDocument->fStopAllEditions) && fSectionHandle && (this->GetUpdateMode() == pumOnSave) && this->IsChanged())
  857.     {
  858.         TFile* currentFile = this->GetCurrentFile(aFile);
  859.         if (currentFile)
  860.             this->Publish(currentFile);
  861.         else
  862.             this->Publish(aFile);
  863.     }
  864. } // TPublisher::DoWrite 
  865.  
  866. //----------------------------------------------------------------------------------------
  867. // TPublisher::Delete: 
  868. //----------------------------------------------------------------------------------------
  869. #pragma segment MASectionWrite
  870.  
  871. void TPublisher::Delete()            // override 
  872.  
  873. {
  874.     this->DeleteEditionFile();
  875.  
  876.     Inherited::Delete();
  877. } // TPublisher::Delete 
  878.  
  879. //----------------------------------------------------------------------------------------
  880. // TPublisher::DeleteEditionFile: 
  881. //----------------------------------------------------------------------------------------
  882. #pragma segment MASectionWrite
  883.  
  884. void TPublisher::DeleteEditionFile()
  885.  
  886. {
  887.     FSSpec theFile;
  888.  
  889.     // get the edition container file's FSSpec - from updated fLastEditionInfo 
  890.     this->UpdateEditionInfo();
  891.     theFile = fLastEditionInfo.container.theFile;
  892.  
  893.     // cancel the section - this unregisters the section 
  894.     this->CancelSection(kCancel);
  895.  
  896.     // delete the edition container file 
  897.     OSErr err = DeleteEditionContainerFile(&theFile);
  898.     if ((err != noErr) && (err != fnfErr))        // allow file-not-found error
  899.         FailOSErr(err);
  900. } // TPublisher::DeleteEditionFile 
  901.  
  902. //----------------------------------------------------------------------------------------
  903. // TPublisher::IsChanged: 
  904. //----------------------------------------------------------------------------------------
  905. #pragma segment MASectionRes
  906.  
  907. Boolean TPublisher::IsChanged()
  908.  
  909. {
  910.     EditionInfoRecord editionInfo;
  911.  
  912.     if (fSectionHandle)
  913.     {
  914.         FailOSErr(GetEditionInfo(fSectionHandle, &editionInfo));
  915.         return editionInfo.mdDate != (*fSectionHandle)->mdDate;
  916.     }
  917.     else
  918.         return FALSE;
  919. } // TPublisher::IsChanged 
  920.  
  921. //----------------------------------------------------------------------------------------
  922. // TPublisher::MarkAsChanged: 
  923. //----------------------------------------------------------------------------------------
  924. #pragma segment MASectionRes
  925.  
  926. void TPublisher::MarkAsChanged()
  927.  
  928. {
  929.     if (fSectionHandle)
  930.     {
  931.         unsigned long secs;
  932.     
  933.         // mark this publisher as changed 
  934.         GetDateTime(&secs);
  935.         (*fSectionHandle)->mdDate = secs;
  936.     }
  937. } // TPublisher::MarkAsChanged 
  938.  
  939.  
  940.  
  941. //========================================================================================
  942. // CLASS TSubscriber
  943. //========================================================================================
  944. #undef Inherited
  945. #define Inherited TSection
  946.  
  947. #pragma segment MASectionNonRes
  948. MA_DEFINE_CLASS_M1(TSubscriber, Inherited);
  949.  
  950. //----------------------------------------------------------------------------------------
  951. // TSubscriber::TSubscriber: Empty constructor to satisfy the compiler.
  952. //----------------------------------------------------------------------------------------
  953. #pragma segment ConstructorRes
  954.  
  955. TSubscriber::TSubscriber()
  956. {
  957. } // TSubscriber::TSubscriber
  958.  
  959. //----------------------------------------------------------------------------------------
  960. // TSubscriber destructor
  961. //----------------------------------------------------------------------------------------
  962. #pragma segment MADestructorRes
  963.  
  964. TSubscriber::~TSubscriber()
  965. {
  966. }
  967.  
  968. //----------------------------------------------------------------------------------------
  969. // TSubscriber::ISubscriber: 
  970. //----------------------------------------------------------------------------------------
  971. #pragma segment MASectionRes
  972.  
  973. void TSubscriber::ISubscriber(TEditionDocument* itsDocument,
  974.                                      TDesignator* itsDesignator,
  975.                                      SectionHandle itsSectionHandle,
  976.                                      short itsRsrcID)
  977.  
  978. {
  979.     this->ISection(itsDocument, itsDesignator, itsSectionHandle, itsRsrcID);
  980.  
  981.     fChanged = FALSE;                    // should be in an Initialize method.
  982.  
  983.     FailInfo fi;
  984.     Try(fi)
  985.     {
  986.         // ensure that the document is notified of any and all changes to the subscriber 
  987.         this->AddDependent(itsDocument);
  988.  
  989.         fi.Success();
  990.     }
  991.     else
  992.     {
  993.         this->Free();
  994.         fi.ReSignal();
  995.     }
  996. } // TSubscriber::ISubscriber 
  997.  
  998. //----------------------------------------------------------------------------------------
  999. // TSubscriber::SubscribeIfNewer: 
  1000. //----------------------------------------------------------------------------------------
  1001. #pragma segment MASectionRead
  1002.  
  1003. void TSubscriber::SubscribeIfNewer()
  1004.  
  1005. {
  1006.     if ((!fDocument->fStopAllEditions) && fSectionHandle && (this->GetUpdateMode() == sumAutomatic) && this->IsNewerEditionAvailable())
  1007.         this->Subscribe();
  1008. } // TSubscriber::SubscribeIfNewer 
  1009.  
  1010. //----------------------------------------------------------------------------------------
  1011. // TSubscriber::Subscribe: 
  1012. //----------------------------------------------------------------------------------------
  1013. #pragma segment MASectionRead
  1014.  
  1015. void TSubscriber::Subscribe()
  1016.  
  1017. {
  1018.     Size formatSize;
  1019.     OSErr err;
  1020.  
  1021.     MAVolatile(TSectionStream*, aSectionStream);
  1022.     //MAVolatile(EditionRefNum, refNum);
  1023.     EditionRefNum refNum;    // can't be volatile because it is passed by reference
  1024.  
  1025.     FailOSErr(OpenEdition(fSectionHandle, &refNum));
  1026.  
  1027.     FailInfo fi;
  1028.     Try(fi)
  1029.     {
  1030.         // Create a section stream to read the published data from.
  1031.         aSectionStream = NULL;
  1032.         aSectionStream = new TSectionStream;
  1033.         aSectionStream->ISectionStream(refNum, '    ');
  1034.         
  1035.         FailInfo innerfi;
  1036.         Try(innerfi)
  1037.         {
  1038.             // Top priority: subscribe to private types.
  1039.             err = EditionHasFormat(refNum, fDocument->fScrapType, &formatSize);
  1040.             if ((err == noErr) && (formatSize > 0))
  1041.             {
  1042.                 aSectionStream->Reset(fDocument->fScrapType, formatSize);
  1043.                 fDocument->DoReadData(fDocument->fScrapType, fDesignator, aSectionStream, formatSize);
  1044.             }
  1045.             else
  1046.             {
  1047.                 // subscribe to one or more of the required data types 
  1048.                 err = EditionHasFormat(refNum, 'PICT', &formatSize);
  1049.                 if ((err == noErr) && (formatSize > 0))
  1050.                 {
  1051.                     aSectionStream->Reset('PICT', formatSize);
  1052.                     fDocument->DoReadData('PICT', fDesignator, aSectionStream, formatSize);
  1053.                 }
  1054.                 err = EditionHasFormat(refNum, 'TEXT', &formatSize);
  1055.                 if ((err == noErr) && (formatSize > 0))
  1056.                 {
  1057.                     aSectionStream->Reset('TEXT', formatSize);
  1058.                     fDocument->DoReadData('TEXT', fDesignator, aSectionStream, formatSize);
  1059.                 }
  1060.                 err = EditionHasFormat(refNum, 'snd ', &formatSize);
  1061.                 if ((err == noErr) && (formatSize > 0))
  1062.                 {
  1063.                     aSectionStream->Reset('snd ', formatSize);
  1064.                     fDocument->DoReadData('snd ', fDesignator, aSectionStream, formatSize);
  1065.                 }
  1066.             }
  1067.             innerfi.Success();
  1068.         }
  1069.         else
  1070.         {
  1071.             // Free the stream
  1072.             aSectionStream = (TSectionStream*)FreeIfObject(aSectionStream);
  1073.             innerfi.ReSignal();
  1074.         }
  1075.         
  1076.         // Free the stream
  1077.         aSectionStream->Free();
  1078.  
  1079.         fi.Success();
  1080.     }
  1081.     else    // Recover
  1082.     {
  1083.         // If there is a failure during subscribing, close the edition file without saving
  1084.         // the changes (pass false for successful). This ensures that the subscriber will
  1085.         // get a shot at subscribing again later.
  1086.         err = CloseEdition(refNum, FALSE);
  1087.  
  1088.         fi.ReSignal();                            // Optional. Omit to continue.
  1089.     }
  1090.  
  1091.     // close the edition file 
  1092.     FailOSErr(CloseEdition(refNum, TRUE));
  1093.  
  1094.     // adjust this guy's border
  1095.     fDocument->DoAdjustBorder(this);
  1096.  
  1097.     this->Changed(cSubscriberChanged, this);    // notify dependents 
  1098. } // TSubscriber::Subscribe 
  1099.  
  1100. //----------------------------------------------------------------------------------------
  1101. // TSubscriber::IsNewerEditionAvailable: 
  1102. //----------------------------------------------------------------------------------------
  1103. #pragma segment MASectionRes
  1104.  
  1105. Boolean TSubscriber::IsNewerEditionAvailable()
  1106.  
  1107. {
  1108.     EditionInfoRecord editionInfo;
  1109.  
  1110.     if (fSectionHandle)
  1111.     {
  1112.         FailOSErr(GetEditionInfo(fSectionHandle, &editionInfo));
  1113.         return (editionInfo.mdDate != (*fSectionHandle)->mdDate);
  1114.     }
  1115.     else
  1116.         return FALSE;
  1117. } // TSubscriber::IsNewerEditionAvailable 
  1118.  
  1119. //----------------------------------------------------------------------------------------
  1120. // TSubscriber::OpenPublisher: 
  1121. //----------------------------------------------------------------------------------------
  1122. #pragma segment MASectionRes
  1123.  
  1124. void TSubscriber::OpenPublisher()
  1125.  
  1126. {
  1127.     EditionInfoRecord editionInfo;
  1128.  
  1129.     FailOSErr(GetEditionInfo(fSectionHandle, &editionInfo));
  1130.     FailOSErr(GoToPublisherSection(&(editionInfo.container)));
  1131. } // TSubscriber::OpenPublisher 
  1132.  
  1133.  
  1134. //----------------------------------------------------------------------------------------
  1135. // TSubscriber::IsChanged: 
  1136. //----------------------------------------------------------------------------------------
  1137. #pragma segment MASectionRes
  1138.  
  1139. Boolean TSubscriber::IsChanged()
  1140.  
  1141. {
  1142.     return fChanged;
  1143. } // TSubscriber::IsChanged 
  1144.  
  1145. //----------------------------------------------------------------------------------------
  1146. // TSubscriber::MarkAsChanged: 
  1147. //----------------------------------------------------------------------------------------
  1148. #pragma segment MASectionRes
  1149.  
  1150. void TSubscriber::MarkAsChanged()
  1151.  
  1152. {
  1153.     fChanged = TRUE;
  1154. } // TSubscriber::MarkAsChanged 
  1155.  
  1156.  
  1157. //========================================================================================
  1158. // CLASS TSectionStream
  1159. //========================================================================================
  1160. #undef Inherited
  1161. #define Inherited TStream
  1162.  
  1163. #pragma segment MASectionNonRes
  1164. MA_DEFINE_CLASS_M1(TSectionStream, Inherited);
  1165.  
  1166. //----------------------------------------------------------------------------------------
  1167. // TSectionStream constructor
  1168. //----------------------------------------------------------------------------------------
  1169. #pragma segment MAStreamCreate
  1170.  
  1171. TSectionStream::TSectionStream()
  1172. {
  1173.     fEditionRefNum = 0;
  1174.     fEditionOSType = kNoIdentifier;
  1175.     fPosition = 0;
  1176.     fSize = 0;
  1177. } // TSectionStream::TSectionStream
  1178.  
  1179. //----------------------------------------------------------------------------------------
  1180. // TSectionStream destructor
  1181. //----------------------------------------------------------------------------------------
  1182. #pragma segment MADestructorRes
  1183.  
  1184. TSectionStream::~TSectionStream()
  1185. {
  1186. }
  1187.  
  1188. //----------------------------------------------------------------------------------------
  1189. // TSectionStream::ISectionStream: 
  1190. //----------------------------------------------------------------------------------------
  1191. #pragma segment MAStreamCreate
  1192.  
  1193. void TSectionStream::ISectionStream(EditionRefNum itsEditionRefNum, OSType itsEditionOSType)
  1194. {
  1195.     this->IStream();
  1196.  
  1197.     fEditionRefNum = itsEditionRefNum;
  1198.     fEditionOSType = itsEditionOSType;
  1199. } // TSectionStream::ISectionStream 
  1200.  
  1201. //----------------------------------------------------------------------------------------
  1202. // TSectionStream::Reset: 
  1203. //----------------------------------------------------------------------------------------
  1204. #pragma segment MASectionWrite
  1205.  
  1206. void TSectionStream::Reset(OSType itsEditionOSType, long itsSize)
  1207. {
  1208.     this->SetPosition(0);
  1209.     fEditionOSType = itsEditionOSType;
  1210.     fSize = itsSize;
  1211. } // TSectionStream::Reset 
  1212.  
  1213. //----------------------------------------------------------------------------------------
  1214. // TSectionStream::GetPosition: 
  1215. //----------------------------------------------------------------------------------------
  1216. #pragma segment MAStreamUtil
  1217.  
  1218. long TSectionStream::GetPosition()    // override 
  1219. {
  1220.     return fPosition;
  1221. } // TSectionStream::GetPosition 
  1222.  
  1223. //----------------------------------------------------------------------------------------
  1224. // TSectionStream::SetPosition: 
  1225. //----------------------------------------------------------------------------------------
  1226. #pragma segment MAStreamUtil
  1227.  
  1228. void TSectionStream::SetPosition(long newPosition)// override 
  1229. {
  1230.     fPosition = newPosition;
  1231.  
  1232.     if (fPosition > fSize)                        // Adjust the size if necessary. 
  1233.         fSize = fPosition;
  1234. } // TSectionStream::SetPosition 
  1235.  
  1236. //----------------------------------------------------------------------------------------
  1237. // TSectionStream::GetSize: 
  1238. //----------------------------------------------------------------------------------------
  1239. #pragma segment MAStreamUtil
  1240.  
  1241. long TSectionStream::GetSize()
  1242. {
  1243.     return fSize;
  1244. } // TSectionStream::GetSize 
  1245.  
  1246. //----------------------------------------------------------------------------------------
  1247. // TSectionStream::SetSize: 
  1248. //----------------------------------------------------------------------------------------
  1249. #pragma segment MAStreamUtil
  1250.  
  1251. void TSectionStream::SetSize(long newSize)// override 
  1252. {
  1253.     fSize = newSize;
  1254.  
  1255.     if (newSize < fPosition)                    // If we shrunk the size, then we have to adjust the position.
  1256.         fPosition = newSize;
  1257. } // TSectionStream::SetSize 
  1258.  
  1259. //----------------------------------------------------------------------------------------
  1260. // TSectionStream::WriteBytes: 
  1261. //----------------------------------------------------------------------------------------
  1262. #pragma segment MAStreamWrite
  1263.  
  1264. void TSectionStream::WriteBytes(const void* p, long count)
  1265. {
  1266.     FailOSErr(SetEditionFormatMark(fEditionRefNum, fEditionOSType, this->GetPosition()));
  1267.     FailOSErr(WriteEdition(fEditionRefNum, fEditionOSType, p, count));
  1268.  
  1269.     this->SetPosition(fPosition + count);        // Advance the position. 
  1270. } // TSectionStream::WriteBytes 
  1271.  
  1272. //----------------------------------------------------------------------------------------
  1273. // TSectionStream::ReadBytes: 
  1274. //----------------------------------------------------------------------------------------
  1275. #pragma segment MAStreamRead
  1276.  
  1277. void TSectionStream::ReadBytes(void* p, long count)    // override 
  1278. {
  1279.     FailOSErr(SetEditionFormatMark(fEditionRefNum, fEditionOSType, this->GetPosition()));
  1280.     FailOSErr(ReadEdition(fEditionRefNum, fEditionOSType, p, &count));
  1281.  
  1282.     this->SetPosition(fPosition + count);        // Advance the position. 
  1283. } // TSectionStream::ReadBytes 
  1284.  
  1285.  
  1286.  
  1287. //========================================================================================
  1288. // CLASS TSectionList
  1289. //========================================================================================
  1290. #undef Inherited
  1291. #define Inherited TSortedList
  1292.  
  1293. #pragma segment MASectionNonRes
  1294. MA_DEFINE_CLASS_M1(TSectionList, Inherited);
  1295.  
  1296. //----------------------------------------------------------------------------------------
  1297. // TSectionList::TSectionList: Empty constructor to satisfy the compiler.
  1298. //----------------------------------------------------------------------------------------
  1299. #pragma segment ConstructorRes
  1300.  
  1301. TSectionList::TSectionList()
  1302. {
  1303. } // TSectionList::TSectionList
  1304.  
  1305. //----------------------------------------------------------------------------------------
  1306. // TSectionList destructor
  1307. //----------------------------------------------------------------------------------------
  1308. #pragma segment MADestructorRes
  1309.  
  1310. TSectionList::~TSectionList()
  1311. {
  1312. }
  1313.  
  1314. //----------------------------------------------------------------------------------------
  1315. // TSectionList::ISectionList:
  1316. //----------------------------------------------------------------------------------------
  1317. #pragma segment MASectionRes
  1318.  
  1319. void TSectionList::ISectionList()
  1320. {
  1321.     this->ISortedList();
  1322. } // TEntriesList::ISectionList
  1323.  
  1324. //----------------------------------------------------------------------------------------
  1325. // TSectionList::Compare:
  1326. //----------------------------------------------------------------------------------------
  1327. #pragma segment MASectionRes
  1328.  
  1329. CompareResult TSectionList::Compare(TObject* item1,
  1330.                                    TObject* item2)
  1331. {
  1332.     TSection* section1 = (TSection*) item1;
  1333.     TSection* section2 = (TSection*) item2;
  1334.  
  1335.     if ((*(section1->fSectionHandle))->controlBlock < (*(section2->fSectionHandle))->controlBlock)
  1336.         return kItem1LessThanItem2;
  1337.     else if ((*(section1->fSectionHandle))->controlBlock > (*(section2->fSectionHandle))->controlBlock)
  1338.         return kItem1GreaterThanItem2;
  1339.     else
  1340.         return kItem1EqualItem2;
  1341. } // TSectionList::Compare
  1342.  
  1343. //----------------------------------------------------------------------------------------
  1344. // End of USection.cp
  1345.  
  1346. #pragma segment Inline
  1347.